﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibMinecraft.Server;
using System.IO;
using LibMinecraft.Model.Packets;
using LibMinecraft.Model;

namespace PartyCraftServer.Commands
{
    public class InstallCommand : Command
    {
        public override bool RequiresOp
        {
            get { return true; }
        }

        public override string DefaultCommand
        {
            get { return "install"; }
        }

        public override string Documentation
        {
            get { return "Installs a plugin on the server (may require a restart).\nUsage: /install [path]\n[path] should point to the plugin DLL (no spaces)."; }
        }

        public override void ExecuteCommand(RemoteClient client, params string[] parameters)
        {
            if (parameters.Length != 1)
            {
                client.SendChat(ChatColor.Red + "Invalid parameters. Use /install [path].");
                client.SendChat(ChatColor.Red + "[path] may not include spaces.");
                return;
            }
            if (!File.Exists(parameters[0]))
            {
                client.SendChat(ChatColor.Red + "Plugin file not found!");
                return;
            }
            if (!Path.IsPathRooted(parameters[0]))
                parameters[0] = Path.Combine(Directory.GetCurrentDirectory(), parameters[0]);
            PartyCraft.PluginManager.InstallPlugin(parameters[0]);
        }
    }
}
